package com.dayu.sale.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.sale.domain.DySaleGoods;
import com.dayu.sale.service.IDySaleGoodsService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 版本3 --- 出售商品信息Controller
 *
 * @author HK
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/sale/goods")
public class DySaleGoodsController extends BaseController
{
    @Autowired
    private IDySaleGoodsService dySaleGoodsService;

    /**
     * 查询版本3 --- 出售商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('sale:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(DySaleGoods dySaleGoods)
    {
        startPage();
        List<DySaleGoods> list = dySaleGoodsService.selectDySaleGoodsList(dySaleGoods);
        return getDataTable(list);
    }

    /**
     * 导出版本3 --- 出售商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('sale:goods:export')")
    @Log(title = "版本3 --- 出售商品信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DySaleGoods dySaleGoods)
    {
        List<DySaleGoods> list = dySaleGoodsService.selectDySaleGoodsList(dySaleGoods);
        ExcelUtil<DySaleGoods> util = new ExcelUtil<DySaleGoods>(DySaleGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 获取版本3 --- 出售商品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dySaleGoodsService.selectDySaleGoodsById(id));
    }

    /**
     * 新增版本3 --- 出售商品信息
     */
    @PreAuthorize("@ss.hasPermi('sale:goods:add')")
    @Log(title = "版本3 --- 出售商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DySaleGoods dySaleGoods)
    {
        return toAjax(dySaleGoodsService.insertDySaleGoods(dySaleGoods));
    }

    /**
     * 修改版本3 --- 出售商品信息
     */
    @PreAuthorize("@ss.hasPermi('sale:goods:edit')")
    @Log(title = "版本3 --- 出售商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DySaleGoods dySaleGoods)
    {
        return toAjax(dySaleGoodsService.updateDySaleGoods(dySaleGoods));
    }
}
